<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\controller\ding;

use app\api\controller\Controller;
use app\api\model\ding\Yuyue as YuyueModel;
use app\api\service\User as UserService;
use app\api\model\store\shop\Clerk as ClerkModel;
use think\response\Json;
use think\facade\Db;
/**
 * 用户预约管理
 * Class Cart
 * @package app\api\controller
 */
class Yuyue extends Controller {

		/*
		*渠道排名
	*/
	public function rankList($date = 0,int $shopId=0): Json {
	
		$service = new ClerkModel;

		$list = $service->rankListYuyue($shopId, $date);

		return $this->renderSuccess(compact('list'));
	}

	public function list(): Json {
		$service = new YuyueModel;
		$list = $service->getList($this->request->param());
		return $this->renderSuccess(compact('list'));
	}

	public function detail(int $orderId) {
		$detail = YuyueModel::getDetail($orderId);
		$time = strtotime('2024-03-23 ' . $detail['time']);
		$time2 = strtotime('2024-03-23 14:30');
		if ($time2 > $time) {
			$detail['type'] = 1; //午餐
		} else {
			$detail['type'] = 2;
		}
		return $this->renderSuccess(compact('detail'));
	}
	public function cancel(int $orderId): Json {
		

		if ($detail->cancel()) {
			return $this->renderSuccess([], '取消成功');
		}
		return $this->renderError($model->getError() ?: '取消失败');
	}

	//用户预约
	public function add(): Json {
		$model = new YuyueModel;
		$id = $model->add($this->postForm());
		return $this->renderSuccess([], '您的预订已提交给您的专属服务经理!');
	}

}
